/****************************************************************************
*                                                                           *
* dxMgr.h -- PROCESSING LPDIRECT3D9 AND LPDIRECT3DDEVICE9                   *
*                                                                           *
* Copyright (c) Ionescu Marius. All rights reserved(2009).                  *
*                                                                           *
****************************************************************************/

#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <string>

class dxCustomVertex;
class dxMeshAnimation;
class dxCamera;
//class dxCollada;
class dxInput;
class dxLight;
class dxMenu;
class dxAnimation;

class dxMgr
{
	public:
		dxMgr(void);
		~dxMgr(void);
		
		int speedState;
		void beginRender(void);
		void endRender(void);
		bool Initialise(HWND hWndX, HINSTANCE hInstX, int width, int height, bool fullscreen);
		bool LoadXFile(const std::string &filename,int startAnimation=0);
		bool LoadXFile2(const std::string &filename,int startAnimation=0);
		bool LoadXFile3(const std::string &filename,int startAnimation=0);
		bool LoadXFile4(const std::string &filename,int startAnimation=0);
		bool setupD3DPRESENT(HWND hWnd, int width, int height, bool fullscreen);
		bool modelRenderState(LPDIRECT3DDEVICE9 d3dd3v);
		bool customVertexRenderState(LPDIRECT3DDEVICE9 d3dd3v);
		bool InitialiseCollada();
		dxCamera *GetCamera() const;
		dxCamera *GetCamera2() const;
		dxCamera *GetCamera3() const;
		dxCamera *GetCamera4() const;
		void ToggleControlsDisplay() {displayControls = !displayControls;}
		LPDIRECT3DDEVICE9 getD3DDevice(); //returns the device

		void YawEntity(float value){m_entityYaw+=value;}
		void PitchEntity(float value){m_entityPitch+=value;}
		void RollEntity(float value){m_entityRoll+=value;}
		void YawEntity2(float value){m_entityYaw2+=value;}
		void PitchEntity2(float value){m_entityPitch2+=value;}
		void RollEntity2(float value){m_entityRoll2+=value;}
		void YawEntity3(float value){m_entityYaw3+=value;}
		void PitchEntity3(float value){m_entityPitch3+=value;}
		void RollEntity3(float value){m_entityRoll3+=value;}
		void MoveForwardUp(void);
		void MoveForwardDown(void);
		void MoveRight(void);
		void MoveLeft(void);
		void MoveUpUp(void);
		void MoveUpDown(void);
		
		void MoveShipXL(void);
		void MoveShipXR(void);
		void MoveShipYU(void);
		void MoveShipYD(void);
		void MoveShipZF(void);
		void MoveShipZB(void);
		void MoveShipZB2(void);

		void displayModel();
		void NextAnimation();
		void AnimateFaster();
		void AnimateSlower();
		
		void setAnimation(unsigned int x);
		void wireFrameMode();
		
		static const int FontSize=14;
		static float retPos;
		
		bool boolMenu;
		bool Loader;
		bool boolMessage;
		bool turnCar3;
		
		D3DXVECTOR3 modelPosition;
		D3DXVECTOR3 modelPosition2;
		D3DXVECTOR3 modelPosition3;
		D3DXVECTOR3 modelPosition4;
		
		void PositionModel1(float x, float y, float z) const;
		float random_number(float low, float high);
		int random_number_int(int start, int end);
		void LoadTexture(LPDIRECT3DTEXTURE9* texture, LPCTSTR filename);
		void DrawTexture(LPDIRECT3DTEXTURE9 texture, RECT texcoords, float x, float y, int a);
		void drawLoader();


	private:
		LPDIRECT3D9 direct3d;
		LPDIRECT3DDEVICE9 d3dd3v;
		D3DPRESENT_PARAMETERS d3dpp;
		LPD3DXFONT m_font;
		LPD3DXEFFECT effect;    // define the effect pointer
		D3DXHANDLE technique;    // define the handle for the best technique
		
		//Loader
		LPD3DXSPRITE d3dspt;
		LPDIRECT3DTEXTURE9 DisplayTexture;

		dxMeshAnimation *modelAnimation;	
		dxMeshAnimation *modelAnimation2;
		dxMeshAnimation *modelAnimation3;
		dxMeshAnimation *modelAnimation4;
		dxCamera *m_camera, *m_camera2, *m_camera3, *m_camera4;
		//dxCollada *objCollada;
		dxInput *objMouse;
		dxLight * objLight;
		dxAnimation* objModel;

		float m_entityYaw,m_entityPitch,m_entityRoll;
		float m_entityYaw2,m_entityPitch2,m_entityRoll2;
		float m_entityYaw3,m_entityPitch3,m_entityRoll3;
		float m_entityYaw4,m_entityPitch4,m_entityRoll4;

		bool displayControls;	
		void DisplayText(float x) const;
		
		void PositionModel2(float x, float y, float z) const;
		void Message(std::string s) const;
		void MousePosition(float x, float y) const;
		
		bool windowed;
		
		dxCustomVertex* customVertex;
		dxMenu* dxMenu;
};		
